class Solution {
public:
    int pre;
    void traversal(TreeNode* root){
      if(root == NULL) return;
      traversal(root->right);
      root->val += pre;
      pre = root->val;
      traversal(root->left);
    }
    
    TreeNode* convertBST(TreeNode* root) {
      pre = 0;
      traversal(root);
      return root;
    }
};
